package rexsee.core.browser.clazz;

import rexsee.core.browser.Browser;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;

public class GestureListener
		implements
		OnDoubleTapListener,
		OnGestureListener {

	private final Browser mBrowser;
	public GestureListener(Browser browser) {
		mBrowser = browser;
	}

	@Override
	public boolean onDoubleTap(MotionEvent e) {
		mBrowser.touchEventInfo.basicAssignment(TouchEventInfo.EVENT_DOUBLECLICK, e);
		mBrowser.eventList.run(Browser.EVENT_ONDOUBLECLICK);
		return false;
	}
	@Override
	public boolean onDoubleTapEvent(MotionEvent e) {
		return false;
	}
	@Override
	public boolean onSingleTapConfirmed(MotionEvent e) {
		return false;
	}
	@Override
	public boolean onDown(MotionEvent e) {
		return false;
	}
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		mBrowser.touchEventInfo.type = TouchEventInfo.EVENT_FLING;
		mBrowser.touchEventInfo.x = Math.round(e1.getX());
		mBrowser.touchEventInfo.y = Math.round(e1.getY());
		mBrowser.touchEventInfo.x2 = Math.round(e2.getX());
		mBrowser.touchEventInfo.y2 = Math.round(e2.getY());
		mBrowser.touchEventInfo.downTime = e2.getDownTime();
		mBrowser.touchEventInfo.eventTime = e2.getEventTime();
		mBrowser.touchEventInfo.velocityX = Math.round(velocityX);
		mBrowser.touchEventInfo.velocityY = Math.round(velocityY);
		mBrowser.eventList.run(Browser.EVENT_ONFLING);
		return false;
	}
	@Override
	public void onLongPress(MotionEvent e) {
		mBrowser.touchEventInfo.basicAssignment(TouchEventInfo.EVENT_LONGPRESS, e);
		mBrowser.eventList.run(Browser.EVENT_ONLONGPRESS);
	}
	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
		return false;
	}
	@Override
	public void onShowPress(MotionEvent e) {
	}
	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}
}
